#include "pch.h"

#include "Model.h"

void Model::Render(
	ID3D11DeviceContext1* Direct3DContext, 
	ModelViewProjectionConstantBuffer ModelViewProjectionBuffer,
	ID3D11Buffer* constantBuffer,
	ID3D11SamplerState* textureSampler,

	float4x4 ModelTransformation,

	ShaderPairLibrary* shaderPairLibray,
	TextureLibrary* textureLibrary,
	ShapeLibrary* shapeLibrary)
{
	// update the model view projection data with
	 ModelViewProjectionBuffer.model = ModelTransformation;

	 // update the constant buffer with the new data
    Direct3DContext->UpdateSubresource(
        constantBuffer,
        0,
        nullptr,
        &ModelViewProjectionBuffer,
        0,
        0
        );

	// get the sgape to use from the shapes library
	Shape* shape = shapeLibrary->GetShape(this->ShapeID);

	// get the shader pair to use
	ShaderPair* shaderPair = shaderPairLibray->GetShaderPair(this->ShaderID);

	// get the Texture to use
	Texture* texture = textureLibrary->GetTexture(this->TextureID);

	shape->Render(
		Direct3DContext,
		constantBuffer,
		shaderPair->InputLayout,
		shaderPair->VertexShader,
		shaderPair->PixelShader,
		texture->textureResourceView,
		textureSampler);
}